package com.qiniuyun.backai.controller;

import cn.hutool.core.lang.UUID;
import com.qiniuyun.backai.common.BaseResponse;
import com.qiniuyun.backai.common.ErrorCode;
import com.qiniuyun.backai.common.ResultUtils;
import com.qiniuyun.backai.exception.ThrowUtils;
import com.qiniuyun.backai.util.AudioUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
@RequestMapping("/audio")
public class AudioController {
    @Autowired
    private AudioUtil audioUtil;
    @GetMapping("/get")
    public BaseResponse<String> getAudio(@RequestParam String prompt) throws IOException, InterruptedException {
        //判空
        ThrowUtils.throwIf(prompt==null, ErrorCode.PARAMS_ERROR);
        //生成UUID
        String s = UUID.randomUUID().toString().replace("-", "").substring(0,10);
        String url=String.format("audio/%s.mp3",s);
        audioUtil.getAudio(prompt,url);
        return ResultUtils.success(url);
    }
}
